import { RouteRecordRaw } from 'vue-router'

const pageTitle = (name: string): string => {
    return `pagesTitle.${name}`
}

/*
 * 静态路由
 */
const staticRoutes: Array<RouteRecordRaw> = [
    {
        // 用户首页
        path: '/',
        name: '/',
        component: () => import('/@/views/frontend/index.vue'),
        meta: {
            title: pageTitle('home'),
        },
    },

    {
        // 会员登录页
        path: '/user/login',
        name: 'userLogin',
        component: () => import('/@/views/frontend/login.vue'),
        meta: {
            title: pageTitle('userLogin'),
        },
    },
    
    {
        // 后台登录页
        path: '/admin/login',
        name: 'adminLogin',
        component: () => import('/@/views/backend/login.vue'),
        meta: {
            title: pageTitle('adminLogin'),
        },
    },
    {
        // 业务报价
        path: '/system/business/quotation/:no',
        name: 'businessQuotation',
        component: () => import('/@/views/most/business/business/quotation/index.vue'),
        meta: {
            title: '业务报价',
        },
    },
    {
        // 直播详情
        path: '/admin/live/detail/:live_id',
        name: 'liveDetail',
        component: () => import('/@/views/backend/live/detail.vue'),
        meta: {
            title: '直播记录详情',
        },
    },
    {
        // 订单详情
        path: '/admin/order/order/detail/:out_trade_no',
        name: 'orderDetail',
        component: () => import('/@/views/backend/order/order/detail.vue'),
        meta: {
            title: '订单详情',
        },
    },
    {
        // 直播详情
        path: '/user/live/detail/:live_id',
        name: 'userLiveDetail',
        component: () => import('/@/views/frontend/live/detail.vue'),
        meta: {
            title: '直播记录详情',
        },
    },
    {
        // 订单详情
        path: '/user/order/order/detail/:out_trade_no',
        name: 'userOrderDetail',
        component: () => import('/@/views/frontend/order/order/detail.vue'),
        meta: {
            title: '订单详情',
        },
    },
    {
        // 合并订单
        path: '/admin/order/merge',
        name: 'adminOrderMerge',
        component: () => import('/@/views/backend/order/merge/index.vue'),
        meta: {
            title: '合并订单',
        },
    },
    {
        // 日用品子订单列表
        path: '/system/daily/suborder/:out_trade_no',
        name: 'system/daily/suborder',
        component: () => import('/@/views/most/daily/suborder/index.vue'),
        meta: {
            title: '子订单列表',
        },
    },
    {
        // 合并订单
        path: '/user/order/merge',
        name: 'userOrderMerge',
        component: () => import('/@/views/frontend/order/merge/index.vue'),
        meta: {
            title: '合并订单',
        },
    },
    {
        // 总后台登录页
        path: '/system/login',
        name: 'systemLogin',
        component: () => import('/@/views/most/login.vue'),
        meta: {
            title: pageTitle('systemLogin'),
        },
    },
    
    {
        path: '/:path(.*)*',
        redirect: '/404',
    },
    {
        // 404
        path: '/404',
        name: 'notFound',
        component: () => import('/@/views/common/error/404.vue'),
        meta: {
            title: pageTitle('notFound'), // 页面不存在
        },
    },
    {
        // 后台找不到页面了-可能是路由未加载上
        path: '/admin:path(.*)*',
        redirect: (to) => {
            return {
                name: 'adminMainLoading',
                params: {
                    to: JSON.stringify({
                        path: to.path,
                        query: to.query,
                    }),
                },
            }
        },
    },
    {
        // 总后台找不到页面了-可能是路由未加载上
        path: '/system:path(.*)*',
        redirect: (to) => {
            return {
                name: 'systemMainLoading',
                params: {
                    to: JSON.stringify({
                        path: to.path,
                        query: to.query,
                    }),
                },
            }
        },
    },
    {
        // 会员中心找不到页面了
        path: '/user:path(.*)*',
        redirect: (to) => {
            return {
                name: 'userMainLoading',
                params: {
                    to: JSON.stringify({
                        path: to.path,
                        query: to.query,
                    }),
                },
            }
        },
    },
    {
        // 无权限访问
        path: '/401',
        name: 'noPower',
        component: () => import('/@/views/common/error/401.vue'),
        meta: {
            title: pageTitle('noPower'),
        },
    },
]

/*
 * 后台基础静态路由
 */
const adminBaseRoute: RouteRecordRaw = {
    path: '/admin',
    name: 'admin',
    component: () => import('/@/layouts/backend/index.vue'),
    redirect: '/admin/loading',
    meta: {
        title: pageTitle('admin'),
    },
    children: [
        {
            path: 'loading/:to?',
            name: 'adminMainLoading',
            component: () => import('/@/layouts/common/components/loading.vue'),
            meta: {
                title: pageTitle('Loading'),
            },
        },
    ],
}

/*
 * 总后台基础静态路由
 */
const systemBaseRoute: RouteRecordRaw = {
    path: '/system',
    name: 'system',
    component: () => import('/@/layouts/most/index.vue'),
    redirect: '/system/loading',
    meta: {
        title: pageTitle('system'),
    },
    children: [
        {
            path: 'loading/:to?',
            name: 'systemMainLoading',
            component: () => import('/@/layouts/common/components/loading.vue'),
            meta: {
                title: pageTitle('Loading'),
            },
        },
    ],
}

/*
 * 会员中心基础静态路由
 */
const userBaseRoute: RouteRecordRaw = {
    path: '/user',
    name: 'user',
    component: () => import('/@/layouts/frontend/index.vue'),
    redirect: '/user/loading',
    meta: {
        title: pageTitle('User'),
    },
    children: [
        {
            path: 'loading/:to?',
            name: 'userMainLoading',
            component: () => import('/@/layouts/common/components/loading.vue'),
            meta: {
                title: pageTitle('Loading'),
            },
        },
    ],
}

staticRoutes.push(adminBaseRoute)
staticRoutes.push(systemBaseRoute)
staticRoutes.push(userBaseRoute)

export { staticRoutes, adminBaseRoute, systemBaseRoute, userBaseRoute }
